﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace csharp_mailsend
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("input host: ");
            string input_host = Console.ReadLine();

            Console.Write("input port: ");
            string input_port = Console.ReadLine();

            Console.Write("input auth user: ");
            string input_auth_user = Console.ReadLine();

            Console.Write("input auth password: ");
            string input_auth_password = Console.ReadLine();

            Console.Write("input from: ");
            string input_from = Console.ReadLine();

            Console.Write("input to: ");
            string input_to = Console.ReadLine();

            Console.Write("input subject: ");
            string input_subject = Console.ReadLine();

            Console.Write("input body: ");
            string input_body = Console.ReadLine();
            
            // Command line argument must the the SMTP host.
            SmtpClient client = new SmtpClient();
            client.Port = input_port;
            client.Host = input_host;
            client.EnableSsl = true;
            client.Timeout = 10000;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential(input_auth_user, input_auth_password);

            MailMessage mm = new MailMessage(input_from, input_to, input_subject, input_body);
            mm.BodyEncoding = UTF8Encoding.UTF8;
            mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

            client.Send(mm);

            Console.Write("press any key...");
            Console.ReadKey();
        }
    }
}
